Skip to main content

Third Party Dependencies

One of the most powerful aspects of the Luna platform is that Contracts are just Python code. This means you can leverage the power of the Python ecosystem directly.

For example, I can import the SendGrid API library and send emails directly from my Contract like so:

from luna import Template, Clause, Parameter, Secret
# using SendGrid's Python Library
# https://github.com/sendgrid/sendgrid-python
import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail


def send_email_via_send_grid(to_address: str, api_key: str):
message = Mail(
from_email='from_email@example.com',
to_emails=to_address,
subject='Sending with Twilio SendGrid is Fun',
html_content='<strong>and easy to do anywhere, even with Python</strong>')

sg = SendGridAPIClient(api_key)
response = sg.send(message)

class MyTemplate(Template):

to_address = Parameter(type_=str)

send_grid_api_key = Secret(name="SEND_GRID_API_KEY")

@clause(occurences=1)
def send_email(self):
send_email_via_send_grid(self.to_address, self.send_grid_api_key)